package com.sqly.doc.menu.fwjl;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.ihidea.multilinechooselib.MultiLineChooseLayout;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sqly.doc.R;
import com.sqly.doc.base.MyBaseActivity;
import com.sqly.doc.menu.camera.CameraChoose;
import com.sqly.doc.pojo.RetMsg;
import com.sqly.doc.pojo.ServiceRecord;
import com.sqly.doc.util.Constants;
import com.sqly.doc.util.CreateBitmap;
import com.sqly.doc.util.DateConvert;
import com.sqly.doc.util.HttpUrl;
import com.sqly.doc.util.MyToastUtil;
import com.sqly.doc.util.NetWorkUtils;
import com.sqly.doc.util.SharedPreferencesUtils;
import com.sqly.doc.util.SweetAlertDialogUtil;
import com.sqly.doc.util.Url;
import com.sqly.doc.util.UserClient;
import com.sqly.doc.view.CustomDatePicker;
import com.sqly.doc.view.StringUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import butterknife.Bind;
import butterknife.ButterKnife;
import cxy.com.validate.IValidateResult;
import cxy.com.validate.Validate;
import cxy.com.validate.annotation.Index;
import cxy.com.validate.annotation.MaxLength;
import cxy.com.validate.annotation.NotNull;
import cxy.com.validate.annotation.RE;
import cz.msebera.android.httpclient.Header;

public class fwjl_add extends MyBaseActivity {

    @Index(1)
    @NotNull(msg = "工作时间不能为空")
    @Bind(R.id.gzsj)
    EditText gzsj;


    @Index(2)
    @MaxLength(length = 20, msg = "最大长度为20个字符")
    @Bind(R.id.zz_qt)
    EditText zz_qt;

    @Index(3)
    @NotNull(msg = "服务方式不能为空")
    @MaxLength(length = 20, msg = "最大长度为20个字符")
    @Bind(R.id.fwfs)
    EditText fwfs;

    @Index(4)
    @RE(re = RE.only_number, msg = "仅可输入数字，请重新输入")
    @Bind(R.id.xy1)
    EditText xy1;

    @Index(5)
    @RE(re = RE.only_number, msg = "仅可输入数字，请重新输入")
    @Bind(R.id.xy2)
    EditText xy2;

    @Index(6)
    @RE(re = Constants.ZZS_YWXS_REGEXP, msg = "仅可输入正整数或小数（小数点后保留一位数字），请重新输入")
    @Bind(R.id.xt)
    EditText xt;

    @Index(7)
    @MaxLength(length = 20, msg = "最大长度为20个字符")
    @Bind(R.id.qtjcjl)
    EditText qtjcjl;

//    @Index(8)
//    @MaxLength(length = 20, msg = "最大长度为20个字符")
//    @Bind(R.id.fyyw)
//    EditText fyyw ;
//
//    @Index(9)
//    @MaxLength(length = 20, msg = "最大长度为20个字符")
//    @Bind(R.id.zjjlyw)
//    EditText zjjlyw ;
//
//    @Index(10)
//    @MaxLength(length = 20, msg = "最大长度为20个字符")
//    @Bind(R.id.zjjl)
//    EditText zjjl ;
//
//    @Index(11)
//    @MaxLength(length = 20, msg = "最大长度为20个字符")
//    @Bind(R.id.zjpcyw)
//    EditText zjpcyw ;
//
//    @Index(12)
//    @MaxLength(length = 20, msg = "最大长度为20个字符")
//    @Bind(R.id.zjpc)
//    EditText zjpc ;
//
//    @Index(13)
//    @MaxLength(length = 20, msg = "最大长度为20个字符")
//    @Bind(R.id.ghyw)
//    EditText ghyw ;
//
//    @Index(14)
//    @MaxLength(length = 20, msg = "最大长度为20个字符")
//    @Bind(R.id.fyff)
//    EditText ghywfyff ;

    @Index(8)
    @MaxLength(length = 20, msg = "最大长度为20个字符")
    @Bind(R.id.zhuanzhen)
    EditText zhuanzhen ;

    @Index(9)
    @MaxLength(length = 20, msg = "最大长度为20个字符")
    @Bind(R.id.qita)
    EditText qita;

    @Index(10)
    @MaxLength(length = 20, msg = "最大长度为20个字符")
    @Bind(R.id.jkzd_qt)
    EditText jkzd_qt;

    @Index(11)
    @MaxLength(length = 20, msg = "最大长度为20个字符")
    @Bind(R.id.qt)
    EditText qt;

    @Bind(R.id.qysj)
    TextView qysj;


    MultiLineChooseLayout zhengzhuang;//服务内容
    MultiLineChooseLayout jiankangzhidao;//健康指导
    private List<String> zzData = new ArrayList<>(), jkzdData = new ArrayList<>();
    private CustomDatePicker customDatePicker;
    Context con = fwjl_add.this;
    //标题
    TextView title, uname, fwnr_name;
    ServiceRecord obj;
    String url = "";
    String signupid = "", signuptime="", jkdah="";
    LinearLayout zz_qt_ll, back, jkzd_qt_ll;
    RadioGroup shfs_xy, shfs_yj, shfs_dl,ywlx, glfy;
    String shfs_xyStr = "",shfs_yjStr = "", shfs_dlStr = "", ywlxStr = "", glfyStr = "";

    ImageView xcqm;
    String xcqmpic ="";
    ImageView xcpaizhao;
    TextView pz_record_id;
    boolean pzChange = false;

    @Override
    protected void initUI() {
        setContentView(R.layout.fwjl_add);
        ButterKnife.bind(this);
        Validate.reg(this);
        signupid = getIntent().getStringExtra("signupid");
        signuptime=getIntent().getStringExtra("signuptime");
        jkdah=getIntent().getStringExtra("jkdah");
        if (getIntent().getStringExtra("type").equals("edit")) {
            obj = (ServiceRecord) getIntent().getExtras().getSerializable("b");
            url = HttpUrl.EditFwjl;
        } else {
            url = HttpUrl.AddFwjl;
            obj = new ServiceRecord();
        }
        init();
        if (getIntent().getStringExtra("type").equals("edit")) {
            if(!StringUtils.isEmpty(obj.getImg2())){
                //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg2(),xcqm);
                ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg2()),xcqm);
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {

        }else if(requestCode == 119){
            String img_record_id = (String) data.getExtras().getString("img_record_id");
            pz_record_id.setText(img_record_id);
            pzChange = true;
            byte[] bis = data.getByteArrayExtra("bitmap");
            Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
            Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
            xcqm.setImageBitmap(bb);
        }
    }


    public void init() {
        qysj.setText(signuptime);
        //gzsj = (EditText) findViewById(R.id.gzsj);
        if (obj != null && !StringUtils.isEmpty(obj.getWork_time())) {
            gzsj.setText(DateConvert.dateToString(DateConvert.toDate(obj.getWork_time(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        final String minJhsj = DateConvert.dateToString(DateConvert.toDate(signuptime, DateConvert.YMDHM), DateConvert.YMDHM);
        gzsj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        gzsj.setText(time.split(" ")[0]);
                    }
                }, minJhsj, DateConvert.getCustomDatePickerEndRq()); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
//                customDatePicker.show(now);
                if (obj != null && !StringUtils.isEmpty(obj.getWork_time())) {
                    customDatePicker.show(DateConvert.dateToString(DateConvert.toDate(obj.getWork_time(), DateConvert.YMD), DateConvert.YMD));
                }else {
                    customDatePicker.show(minJhsj);
                }
            }
        });

        xcqm = (ImageView) findViewById(R.id.xcqm);
        if (obj != null && !StringUtils.isEmpty(obj.getXcqm())) {
            xcqmpic = obj.getXcqm();
            xcqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + xcqmpic + ".jpg"));
        }
        xcqm.setOnClickListener(new CustomerListener());
        //现场拍照
        xcpaizhao = (ImageView) findViewById(R.id.xcpaizhao);
        xcpaizhao.setOnClickListener(new CustomerListener());
        //现场拍照照片id
        pz_record_id = (TextView) findViewById(R.id.pz_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg2())) {
            String[] img2Arr =obj.getImg2().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                Log.i("img2Arr[1]",img2Arr[1]);
                pz_record_id.setText(img2Arr[1]);
            }
        }
        if (obj != null && !StringUtils.isEmpty(obj.getFwfs())) {
            fwfs.setText(obj.getFwfs());
        }
        zhengzhuang = (MultiLineChooseLayout) findViewById(R.id.zz);
        zz_qt_ll = (LinearLayout) findViewById(R.id.zz_qt_ll) ;
        zzData.add("无症状 ");
        zzData.add("头痛头晕");
        zzData.add("乏力");
        zzData.add("视物模糊");
        zzData.add("手脚麻木");
        zzData.add("耳鸣");
        zzData.add("体重下降");
        zzData.add("失眠");
        zzData.add("口干、口渴");
        zzData.add("心悸");
        zzData.add("胸闷");
        zzData.add("胸痛");
        zzData.add("其他");
        zhengzhuang.setList(zzData);
        if (obj != null && !StringUtils.isEmpty(obj.getZz())) {
            if (obj.getZz().contains(",")) {
                String[] ss = obj.getZz().split(",");
                for (int i = 0; i < ss.length; i++) {
                    if (!StringUtils.isEmpty(ss[i])) {
                        if(Integer.parseInt(ss[i])==0){
                            zhengzhuang.setIndexItemSelected(Integer.parseInt(ss[i]));
                        }else{
                            zhengzhuang.setIndexItemSelected(Integer.parseInt(ss[i])-1);
                        }
                        if(Integer.parseInt(ss[i])==14){
                            zz_qt_ll.setVisibility(View.VISIBLE);
                        }
                    }
                }
            } else {
                if(Integer.parseInt(obj.getZz())==0){
                    zhengzhuang.setIndexItemSelected(Integer.parseInt(obj.getZz()));
                }else{
                    zhengzhuang.setIndexItemSelected(Integer.parseInt(obj.getZz())-1);
                }
                if(Integer.parseInt(obj.getZz())==14){
                    zz_qt_ll.setVisibility(View.VISIBLE);
                }
            }
        }else{
            zhengzhuang.setIndexItemSelected(0);
        }
        //单选
        zhengzhuang.setOnItemClickListener(new MultiLineChooseLayout.onItemClickListener() {
            @Override
            public void onItemClick(int position, String text) {
               if("其他".equals(text) && zz_qt_ll.getVisibility() == View.GONE){
                   zz_qt_ll.setVisibility(View.VISIBLE);
               }else if("其他".equals(text) && zz_qt_ll.getVisibility() == View.VISIBLE){
                   zz_qt_ll.setVisibility(View.GONE);
                   zz_qt.setText("");
               }
            }
        });
        //zz_qt = (EditText) findViewById(R.id.zz_qt);
        if (obj != null && !StringUtils.isEmpty(obj.getZz_qt())) {
            zz_qt.setText(obj.getZz_qt());
        }
        //xy1 = (EditText) findViewById(R.id.xy1);
        if (obj != null && !StringUtils.isEmpty(obj.getYbzk_xy1())) {
            xy1.setText(obj.getYbzk_xy1());
        }
        //xy2 = (EditText) findViewById(R.id.xy2);
        if (obj != null && !StringUtils.isEmpty(obj.getYbzk_xy2())) {
            xy2.setText(obj.getYbzk_xy2());
        }
        //xt = (EditText) findViewById(R.id.xt);
        if (obj != null && !StringUtils.isEmpty(obj.getYbzk_xt())) {
            xt.setText(obj.getYbzk_xt());
        }
        //qtjcjl = (EditText) findViewById(R.id.qtjcjl);
        if (obj != null && !StringUtils.isEmpty(obj.getQtjcjl())) {
            qtjcjl.setText(obj.getQtjcjl());
        }
        //吸烟
        shfs_xy = (RadioGroup) findViewById(R.id.xiyan);
        shfs_xy.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.xiyan_fou)
                    shfs_xyStr = "0";
                if (i == R.id.xiyan_shi)
                    shfs_xyStr = "1";
                obj.setShfx_xy(shfs_xyStr);
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getShfx_xy())) {
            switch (Integer.parseInt(obj.getShfx_xy())) {
                case 0:
                    shfs_xy.check(R.id.xiyan_fou);
                    break;
                case 1:
                    shfs_xy.check(R.id.xiyan_shi);
                    break;
            }
        }
        //饮酒
        shfs_yj = (RadioGroup) findViewById(R.id.yinjiu);
        shfs_yj.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.yinjiu_fou)
                    shfs_yjStr = "0";
                if (i == R.id.yinjiu_shi)
                    shfs_yjStr = "1";
                obj.setShfx_yj(shfs_yjStr);
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getShfx_yj())) {
            switch (Integer.parseInt(obj.getShfx_yj())) {
                case 0:
                    shfs_yj.check(R.id.yinjiu_fou);
                    break;
                case 1:
                    shfs_yj.check(R.id.yinjiu_shi);
                    break;
            }
        }
        //生活方式-锻炼
        shfs_dl = (RadioGroup) findViewById(R.id.duanlian);
        shfs_dl.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.duanlian_fou)
                    shfs_dlStr = "0";
                if (i == R.id.duanlian_shi)
                    shfs_dlStr = "1";
                obj.setShfs_dl(shfs_dlStr);
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getShfs_dl())) {
            switch (Integer.parseInt(obj.getShfs_dl())) {
                case 0:
                    shfs_dl.check(R.id.duanlian_fou);
                    break;
                case 1:
                    shfs_dl.check(R.id.duanlian_shi);
                    break;
            }
        }
//        //药物类型
//        ywlx = (RadioGroup) findViewById(R.id.ywlx);
//        ywlx.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup radioGroup, int i) {
//                if (i == R.id.ywlx_wu)
//                    ywlxStr = "0";
//                if (i == R.id.ywlx_jy)
//                    ywlxStr = "1";
//                if (i == R.id.ywlx_jt)
//                    ywlxStr = "2";
//                obj.setYwzd_fyywzl(ywlxStr);
//            }
//        });
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_fyywzl())) {
//            switch (Integer.parseInt(obj.getYwzd_fyywzl())) {
//                case 0:
//                    ywlx.check(R.id.ywlx_wu);
//                    break;
//                case 1:
//                    ywlx.check(R.id.ywlx_jy);
//                    break;
//                case 2:
//                    ywlx.check(R.id.ywlx_jt);
//                    break;
//            }
//        }
//        //规律服药
//        glfy = (RadioGroup) findViewById(R.id.glfy);
//        glfy.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup radioGroup, int i) {
//                if (i == R.id.glfy_fou)
//                    glfyStr = "0";
//                if (i == R.id.glfy_shi)
//                    glfyStr = "1";
//                obj.setYwzd_glfy(glfyStr);
//            }
//        });
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_glfy())) {
//            switch (Integer.parseInt(obj.getYwzd_glfy())) {
//                case 0:
//                    glfy.check(R.id.glfy_fou);
//                    break;
//                case 1:
//                    glfy.check(R.id.glfy_shi);
//                    break;
//            }
//        }
        //健康指导
        jiankangzhidao = (MultiLineChooseLayout) findViewById(R.id.jkzd);
        jkzd_qt_ll = (LinearLayout) findViewById(R.id.jkzd_qt_ll) ;
        jkzdData.add("1、戒烟/减少吸烟量 ");
        jkzdData.add("2、健康饮酒");
        jkzdData.add("3、加强锻炼");
        jkzdData.add("4、减体重");
        jkzdData.add("5、低盐饮食");
        jkzdData.add("6、低糖饮食");
        jkzdData.add("7、低脂饮食");
        jkzdData.add("8、其他");
        jiankangzhidao.setList(jkzdData);
        if (obj != null && !StringUtils.isEmpty(obj.getJkzd())) {
            if (obj.getJkzd().contains(",")) {
                String[] ss = obj.getJkzd().split(",");
                for (int i = 0; i < ss.length; i++) {
                    if (!StringUtils.isEmpty(ss[i])) {
                        if(Integer.parseInt(ss[i])==0){
                            jiankangzhidao.setIndexItemSelected(Integer.parseInt(ss[i]));
                        }else{
                            jiankangzhidao.setIndexItemSelected(Integer.parseInt(ss[i])-1);
                        }
                    }
                    if(Integer.parseInt(ss[i])==8){
                        jkzd_qt_ll.setVisibility(View.VISIBLE);
                    }
                }
            } else {
                if(Integer.parseInt(obj.getJkzd())==0){
                    jiankangzhidao.setIndexItemSelected(Integer.parseInt(obj.getJkzd()));
                }else{
                    jiankangzhidao.setIndexItemSelected(Integer.parseInt(obj.getJkzd())-1);
                }
                if(Integer.parseInt(obj.getJkzd())==8){
                    jkzd_qt_ll.setVisibility(View.VISIBLE);
                }
            }
        }

        //单选
        jiankangzhidao.setOnItemClickListener(new MultiLineChooseLayout.onItemClickListener() {
            @Override
            public void onItemClick(int position, String text) {
                if("8、其他".equals(text) && jkzd_qt_ll.getVisibility() == View.GONE){
                    jkzd_qt_ll.setVisibility(View.VISIBLE);
                }else if("8、其他".equals(text) && jkzd_qt_ll.getVisibility() == View.VISIBLE){
                    jkzd_qt_ll.setVisibility(View.GONE);
                    jkzd_qt.setText("");
                }
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getJkzd_qt())) {
            jkzd_qt.setText(obj.getJkzd_qt());
        }
//        //药物指导-药物名称
//        //fyyw = (EditText) findViewById(R.id.fyyw);
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_fyywmc())) {
//            fyyw.setText(obj.getYwzd_fyywmc());
//        }
//        //zjjlyw = (EditText) findViewById(R.id.zjjlyw);
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_zjjl_yw())) {
//            zjjlyw.setText(obj.getYwzd_zjjl_yw());
//        }
//        //zjjl = (EditText) findViewById(R.id.zjjl);
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_zjjl_ywjl())) {
//            zjjl.setText(obj.getYwzd_zjjl_ywjl());
//        }
//        //zjpcyw = (EditText) findViewById(R.id.zjpcyw);
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_zjpc_yw())) {
//            zjpcyw.setText(obj.getYwzd_zjpc_yw());
//        }
//        //zjpc = (EditText) findViewById(R.id.zjpc);
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_zjpc_ywpc())) {
//            zjpc.setText(obj.getYwzd_zjpc_ywpc());
//        }
//        //ghyw = (EditText) findViewById(R.id.ghyw);
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_ghyw())) {
//            ghyw.setText(obj.getYwzd_ghyw());
//        }
//        //ghywfyff = (EditText) findViewById(R.id.fyff);
//        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_ghyw_fyff())) {
//            ghywfyff.setText(obj.getYwzd_ghyw_fyff());
//        }
        //zhuanzhen = (EditText) findViewById(R.id.zhuanzhen);
        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_zz())) {
            zhuanzhen.setText(obj.getYwzd_zz());
        }
        //qita = (EditText) findViewById(R.id.qita);
        if (obj != null && !StringUtils.isEmpty(obj.getYwzd_qt())) {
            qita.setText(obj.getYwzd_qt());
        }
        if (obj != null && !StringUtils.isEmpty(obj.getQt())) {
            qt.setText(obj.getQt());
        }

        title = (TextView) findViewById(R.id.title);
        uname = (TextView) findViewById(R.id.uname);
        title.setText("服务记录");
        back = (LinearLayout) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        uname.setText("保存");
        uname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ArrayList<Integer> zzlist = zhengzhuang.getAllItemSelectedIndex();
                String zzStrs = "", zzNameStrs = "";
                for (int i = 0; i < zzlist.size(); i++) {
                    zzStrs = zzStrs + "," + (zzlist.get(i) + 1);
                    Integer wz = zzlist.get(i);
                    if(wz == 0) {
                        zzNameStrs = "无症状";
                    }else if(wz == 1) {
                        zzNameStrs = zzNameStrs + "," + "头痛头晕";
                    }else if(wz == 2) {
                        zzNameStrs = zzNameStrs + "," + "乏力";
                    }else if(wz == 3) {
                        zzNameStrs = zzNameStrs + "," + "视物模糊";
                    }else if(wz == 4) {
                        zzNameStrs = zzNameStrs + "," + "手脚麻木";
                    }else if(wz == 5) {
                        zzNameStrs = zzNameStrs + "," + "耳鸣";
                    }else if(wz == 6) {
                        zzNameStrs = zzNameStrs + "," + "体重下降";
                    }else if(wz == 7) {
                        zzNameStrs = zzNameStrs + "," + "失眠";
                    }else if(wz == 8) {
                        zzNameStrs = zzNameStrs + "," + "口干、口渴";
                    }else if(wz == 9) {
                        zzNameStrs = zzNameStrs + "," + "心悸";
                    }else if(wz == 10) {
                        zzNameStrs = zzNameStrs + "," + "胸闷";
                    }else if(wz == 11) {
                        zzNameStrs = zzNameStrs + "," + "胸痛";
                    }else if(wz == 12) {
                        zzNameStrs = zzNameStrs + "," + "其他";
                    }
                }
                if(null != zzStrs && !"".equals(zzStrs) &&  zzStrs.startsWith(",")){
                    zzStrs = zzStrs.substring(1,zzStrs.length());
                }
                if(null != zzNameStrs && !"".equals(zzNameStrs) &&  zzNameStrs.startsWith(",")){
                    zzNameStrs = zzNameStrs.substring(1,zzNameStrs.length());
                }

                ArrayList<Integer> jkzdlist = jiankangzhidao.getAllItemSelectedIndex();
                String jkzdStrs = "", jkzdNameStrs = "";
                for (int i = 0; i < jkzdlist.size(); i++) {
                    jkzdStrs = jkzdStrs + "," + (jkzdlist.get(i) + 1);
                    Integer wz = jkzdlist.get(i);
                    if(wz == 0){
                        jkzdNameStrs = "1、戒烟/减少吸烟量 ";
                    }else if(wz == 1) {
                        jkzdNameStrs = jkzdNameStrs + "," + "2、健康饮酒";
                    }else if(wz == 2) {
                        jkzdNameStrs = jkzdNameStrs + "," + "3、加强锻炼";
                    }else if(wz == 3) {
                        jkzdNameStrs = jkzdNameStrs + "," + "4、减体重";
                    }else if(wz == 4) {
                        jkzdNameStrs = jkzdNameStrs + "," + "5、低盐饮食";
                    }else if(wz == 5) {
                        jkzdNameStrs = jkzdNameStrs + "," + "6、低糖饮食";
                    }else if(wz == 6) {
                        jkzdNameStrs = jkzdNameStrs + "," + "7、低脂饮食";
                    }else if(wz == 7) {
                        jkzdNameStrs = jkzdNameStrs + "," + "8、其他";
                    }
                }
                if(null != jkzdStrs && !"".equals(jkzdStrs) &&  jkzdStrs.startsWith(",")){
                    jkzdStrs = jkzdStrs.substring(1,jkzdStrs.length());
                }
                if(null != jkzdNameStrs && !"".equals(jkzdNameStrs) &&  jkzdNameStrs.startsWith(",")){
                    jkzdNameStrs = jkzdNameStrs.substring(1,jkzdNameStrs.length());
                }

                final String finalZzStrs = zzStrs, finalZzNameStrs = zzNameStrs, finalJkzdStrs = jkzdStrs, finalJkzdNameStrs = jkzdNameStrs;
                Validate.check(con, new IValidateResult() {
                    @Override
                    public void onValidateSuccess() {
                        //验证成功,耗时 " + runTime + " 毫秒", Toast.LENGTH_SHORT).show();
                        saveData(finalZzStrs, finalZzNameStrs, finalJkzdStrs, finalJkzdNameStrs);
                    }
                    @Override
                    public void onValidateError(String msg, View view) {
                        view.setFocusable(true);
                        //Toast.makeText(jzyy_add.this, msg, Toast.LENGTH_SHORT).show();
                        SweetAlertDialogUtil.WarningDialog(con, "提示", msg);
                    }

                    @Override
                    public Animation onValidateErrorAnno() {
                        return null;
                    }
                });
            }
        });
    }
    @Override
    protected void initData() {

    }
    @Override
    protected void initListener() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Validate.unreg(this);
    }

    private void saveData(String zzStrs, String zzNameStrs, String jkzdStrs, String jkzdNameStrs){
        //保存
        String xyz1 = xy1.getText().toString(), xyz2 = xy2.getText().toString();
        if(null == zzStrs || "".equals(zzStrs)){
            SweetAlertDialogUtil.WarningDialog(con, "提示", "请选择症状");
        }else if(null != xyz1 && !"".equals(xyz1) && (null == xyz2 || "".equals(xyz2))){
            SweetAlertDialogUtil.WarningDialog(con, "提示", "血压必须高压、低压同时输入");
        } else if(null != xyz2 && !"".equals(xyz2) && (null == xyz1 || "".equals(xyz1))){
            SweetAlertDialogUtil.WarningDialog(con, "提示", "血压必须高压、低压同时输入");
        } else {
            if (obj == null)
                obj = new ServiceRecord();

            obj.setWork_time(gzsj.getText().toString());
            obj.setFwfs(fwfs.getText().toString());
            obj.setZz(zzStrs);
            obj.setZz_name(zzNameStrs);
            obj.setZz_qt(zz_qt.getText().toString());
            obj.setYbzk_xy1(xy1.getText().toString());
            obj.setYbzk_xy2(xy2.getText().toString());
            obj.setYbzk_xt(xt.getText().toString());
            obj.setQtjcjl(qtjcjl.getText().toString());
            obj.setPz_record_id(pz_record_id.getText().toString());
//            obj.setYwzd_fyywmc(fyyw.getText().toString());
//            obj.setYwzd_zjjl_yw(zjjlyw.getText().toString());
//            obj.setYwzd_zjjl_ywjl(zjjl.getText().toString());
//            obj.setYwzd_zjpc_yw(zjpcyw.getText().toString());
//            obj.setYwzd_zjpc_ywpc(zjpc.getText().toString());
//            obj.setYwzd_ghyw(ghyw.getText().toString());
//            obj.setYwzd_ghyw_fyff(ghywfyff.getText().toString());
            obj.setYwzd_zz(zhuanzhen.getText().toString());
            obj.setYwzd_qt(qita.getText().toString());
            obj.setJkzd(jkzdStrs);
            obj.setJkzd_name(jkzdNameStrs);
            obj.setJkzd_qt(jkzd_qt.getText().toString());
            obj.setQt(qt.getText().toString());

            if (NetWorkUtils.isNetworkConnected(con)) {
                RequestParams ps = new RequestParams();
                ps.add("entity.sign_up_id", signupid);
                ps.add("entity.work_time", obj.getWork_time());
                ps.add("entity.fwfs",obj.getFwfs());
                ps.add("entity.zz", obj.getZz());
                ps.add("entity.zz_name", obj.getZz_name());
                ps.add("entity.zz_qt", obj.getZz_qt());
                ps.add("entity.ybzk_xy1", obj.getYbzk_xy1());
                ps.add("entity.ybzk_xy2", obj.getYbzk_xy2());
                ps.add("entity.ybzk_xt", obj.getYbzk_xt());
                ps.add("entity.qtjcjl", obj.getQtjcjl());
                ps.add("entity.shfx_xy", obj.getShfx_xy());
                ps.add("entity.shfx_yj", obj.getShfx_yj());
                ps.add("entity.shfs_dl", obj.getShfs_dl());
//                ps.add("entity.ywzd_fyywmc", obj.getYwzd_fyywmc());
//                ps.add("entity.ywzd_fyywzl", obj.getYwzd_fyywzl());
//                ps.add("entity.ywzd_glfy", obj.getYwzd_glfy());
//                ps.add("entity.ywzd_zjjl_yw", obj.getYwzd_zjjl_yw());
//                ps.add("entity.ywzd_zjjl_ywjl", obj.getYwzd_zjjl_ywjl());
//                ps.add("entity.ywzd_zjpc_yw", obj.getYwzd_zjpc_yw());
//                ps.add("entity.ywzd_zjpc_ywpc", obj.getYwzd_zjpc_ywpc());
//                ps.add("entity.ywzd_ghyw", obj.getYwzd_ghyw());
//                ps.add("entity.ywzd_ghyw_fyff", obj.getYwzd_ghyw_fyff());
                ps.add("entity.ywzd_zz", obj.getYwzd_zz());
                ps.add("entity.ywzd_qt", obj.getYwzd_qt());
                ps.add("entity.jkzd", obj.getJkzd());
                ps.add("entity.jkzd_name", obj.getJkzd_name());
                ps.add("entity.jkzd_qt", obj.getJkzd_qt());
                ps.add("entity.qt", obj.getQt());
                if (getIntent().getStringExtra("type").equals("edit"))
                    ps.add("entity.id", obj.getSrid());
                ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
                ps.add("type", "2");
                ps.add("pz_record_id", obj.getPz_record_id());
                UserClient.get(url, ps, new AsyncHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                        String content = new String(response);
                        RetMsg ret = JSON.parseObject(content, RetMsg.class);
                        if (ret.getCode().equals("200")) {
                            MyToastUtil.ShowToast(con, "成功");
                        }else{
                            MyToastUtil.ShowToast(con, ret.getInfo());
                        }
                        finish();
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                        MyToastUtil.ShowToast(con, "失败");
                    }
                });
            }
        }
    }

    class CustomerListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (getIntent().getStringExtra("type").equals("edit")) {
                Intent intent = new Intent(con, CameraChoose.class)
                        .putExtra("type", "edit")
                        .putExtra("cardnum", jkdah)
                        .putExtra("tabId", null==obj.getSrid()||"".equals(obj.getSrid()) ? "noid" : obj.getSrid())
                        .putExtra("tabType", "ServiceRecord")
                        .putExtra("class", "fwjl_add.class");
                startActivityForResult(intent, 119);
            } else {
                Intent intent = new Intent(con, CameraChoose.class)
                        .putExtra("type", "edit")
                        .putExtra("cardnum", jkdah)
                        .putExtra("tabId", null==obj.getSrid()||"".equals(obj.getSrid()) ? "noid" : obj.getSrid())
                        .putExtra("tabType", "ServiceRecord")
                        .putExtra("class", "fwjl_add.class");
                startActivityForResult(intent, 119);
            }
        }
    }
}
